package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.IntRange;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.bumptech.glide.Glide;
import com.fondesa.recyclerviewdivider.DividerDecoration;
import com.sgb.kjwl.R;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.databinding.PopwindowMapQuoteBinding;
import com.sgb.kjwl.model.entity.self.OrderQuoteEntity;
import com.sgb.kjwl.model.entity.transport.SingleItemEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.DefaultUtil;
import com.sgb.kjwl.utils.NumberUtil;
import com.swgk.core.util.UserOperating;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.event.LogisticsEvent;
import com.sgb.kjwl.view.ui.activity.transport.BiddingOrderDetailsActivity;
import com.sgb.kjwl.view.ui.adapter.transport.MapQuoteInfoAdapter;
import com.sgb.net.util.RequestUtil;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.dialog.RoundDialog;
import com.swgk.core.util.DateUtils;
import com.im.immodel.IMUtils;
import com.swgk.core.util.MToast;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;

/**
 * @author: 杨畔
 * @date: 2021/8/26 10:39
 * @Description: 报价地图窗口
 */
public class MapQuotePopWindow extends BasePopWindow<Object> implements View.OnClickListener {
    private PopwindowMapQuoteBinding mBinding;
    private OrderQuoteEntity mEntity;
    //弹窗类型 0:货主视角弹窗 1:其他人视角弹窗
    private final int mWindowType;
    //信息适配器
    private List<SingleItemEntity> mList;
    private MapQuoteInfoAdapter mAdapter;
    //同意报价/接单回调
    private final CallBack mCallBack;

    public interface CallBack {
        void agreedOffer(OrderQuoteEntity entity);
    }

    private MapQuotePopWindow(Context context, int windowType, CallBack callBack) {
        super(context, DIR_DOWN_UP);
        mWindowType = windowType;
        mCallBack = callBack;
    }

    public static MapQuotePopWindow newInstance(Context context, @IntRange(from = 0, to = 1) int windowType, CallBack callBack) {
        return new MapQuotePopWindow(context, windowType, callBack);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_map_quote;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        mBinding = (PopwindowMapQuoteBinding) holder.getmBinding();
        mBinding.setOnClick(this);
        initRecycler();
    }

    private void initRecycler() {
        mList = new ArrayList<>();
        mAdapter = new MapQuoteInfoAdapter(mList);
        mBinding.rvInfo.setLayoutManager(new LinearLayoutManager(mContext));
        DividerDecoration.builder(mContext)
                .color(Color.TRANSPARENT)
                .size(10, TypedValue.COMPLEX_UNIT_DIP)
                .showLastDivider()
                .build()
                .addTo(mBinding.rvInfo);
        mBinding.rvInfo.setAdapter(mAdapter);
    }

    /**
     * 设置数据
     */
    public void setData(OrderQuoteEntity entity) {
        mEntity = entity;
        if (mEntity == null) return;
        //设置头像
        Glide.with(mContext).load(DefaultUtil.getString(entity.getLogo()))
                .placeholder(R.drawable.icon_default_profile_photo_round)
                .error(R.drawable.icon_default_profile_photo_round)
                .circleCrop()
                .into(mBinding.ivAvatar);
        //重置底部操作按钮
        resetOperatingBtn();
        //弹窗类型 0:货主视角弹窗 1:其他人视角弹窗
        if (mWindowType == 0) {
            syncOwnerWindow();
        } else if (mWindowType == 1) {
            syncOtherWindow();
        } else {
            mList.clear();
            mAdapter.notifyDataSetChanged();
            mBinding.clOperating.setVisibility(View.GONE);
        }
    }

    public OrderQuoteEntity getData() {
        return mEntity;
    }

    /**
     * 重置操作按钮
     */
    private void resetOperatingBtn() {
        mBinding.clOperating.setVisibility(View.VISIBLE);
        mBinding.groupContact.setVisibility(View.VISIBLE);
        mBinding.tvBtn.setVisibility(View.VISIBLE);
        //设置按钮状态
        setContactStatus(mEntity);
    }

    /**
     * 同步其他人视角窗口信息
     */
    private void syncOtherWindow() {
        if (mEntity == null) return;
        mBinding.tvTitle.setText("报价详情");
        //1 企业 2 团队 3 个人
        switch (mEntity.getOfferType()) {
            case "1":
                initCompanyQuoteOtherWindow();
                break;
            case "2":
                initTeamQuoteOtherWindow();
                break;
            case "3":
                initPersonQuoteOtherWindow();
                break;
        }

    }

    /**
     * 设置其他人视角公司报价窗口信息
     */
    private void initCompanyQuoteOtherWindow() {
        mList.clear();
        mList.add(new SingleItemEntity("运费报价",
                String.format("%s元/吨", NumberUtil.trim0(mEntity.getFreight())),
                R.color.color_FF6600));
        mList.add(new SingleItemEntity("地址", getAddress(mEntity)));
        mList.add(new SingleItemEntity("距装货地", getDistanceStr(mEntity.getDistance())));
        mAdapter.notifyDataSetChanged();
        //判断报价是否是自己发布
        if ("1".equals(mEntity.getIsSelfOffer())) {
            mBinding.tvName.setText(DefaultUtil.getString(mEntity.getCompanyName()));
            //判断是否已生成订单 1已报价  2已同意  5货主未同意
            if ("2".equals(mEntity.getOfferStatus())) {
                //报价已被同意
                mBinding.groupContact.setVisibility(View.GONE);
                mBinding.tvBtn.setVisibility(View.VISIBLE);
                mBinding.tvBtn.setText("查看订单");
            } else {
                mBinding.clOperating.setVisibility(View.GONE);
            }
        } else {
            mBinding.tvName.setText(DefaultUtil.getEncryptedString(mEntity.getCompanyName(), 2));
            mBinding.clOperating.setVisibility(View.GONE);
        }
    }

    /**
     * 设置其他人视角团队报价窗口信息
     */
    private void initTeamQuoteOtherWindow() {
        mList.clear();
        mList.add(new SingleItemEntity("运费报价",
                String.format("%s元/吨", NumberUtil.trim0(mEntity.getFreight())),
                R.color.color_FF6600));
        mList.add(new SingleItemEntity("地址", getAddress(mEntity)));
        mList.add(new SingleItemEntity("距装货地", getDistanceStr(mEntity.getDistance())));
        mAdapter.notifyDataSetChanged();
        //判断报价是否是自己发布
        if ("1".equals(mEntity.getIsSelfOffer())) {
            mBinding.tvName.setText(DefaultUtil.getString(mEntity.getTeamName()));
            //判断是否已生成订单 1已报价  2已同意  5货主未同意
            if ("2".equals(mEntity.getOfferStatus())) {
                //报价已被同意
                mBinding.groupContact.setVisibility(View.GONE);
                mBinding.tvBtn.setVisibility(View.VISIBLE);
                mBinding.tvBtn.setText("查看订单");
            } else {
                mBinding.clOperating.setVisibility(View.GONE);
            }
        } else {
            mBinding.tvName.setText(DefaultUtil.getEncryptedString(mEntity.getTeamName(), 2));
            mBinding.clOperating.setVisibility(View.GONE);
        }
    }

    /**
     * 设置其他人视角个人报价窗口信息
     */
    private void initPersonQuoteOtherWindow() {
        mList.clear();
        mList.add(new SingleItemEntity("运费报价",
                String.format("%s元/吨", NumberUtil.trim0(mEntity.getFreight())),
                R.color.color_FF6600));
        mList.add(new SingleItemEntity("承运车辆", getCarInfo(mEntity, !"1".equals(mEntity.getIsSelfOffer()))));
        mList.add(new SingleItemEntity("车辆位置", getAddress(mEntity)));
        mList.add(new SingleItemEntity("距装货地", getDistanceStr(mEntity.getDistance())));
        mAdapter.notifyDataSetChanged();
        //判断报价是否是自己发布
        if ("1".equals(mEntity.getIsSelfOffer())) {
            mBinding.tvName.setText(DefaultUtil.getString(mEntity.getName()));
            //判断是否已生成订单 1已报价  2已同意  5货主未同意
            if ("2".equals(mEntity.getOfferStatus())) {
                //报价已被同意
                mBinding.groupContact.setVisibility(View.GONE);
                mBinding.tvBtn.setVisibility(View.VISIBLE);
                mBinding.tvBtn.setText("查看订单");
            } else {
                mBinding.clOperating.setVisibility(View.GONE);
            }
        } else {
            mBinding.tvName.setText(DefaultUtil.getSuffixString(mEntity.getName(), 1, "师傅"));
            mBinding.clOperating.setVisibility(View.GONE);
        }
    }

    /**
     * 同步货主视角窗口信息
     */
    private void syncOwnerWindow() {
        if (mEntity == null) return;
        //isVoluntarily 报价 0  接单 2
        //offerType 1 企业 2 团队 3 个人
        if (mEntity.getIsVoluntarily() == 2) {
            //接单
            mBinding.tvTitle.setText("接单详情");
            switch (mEntity.getOfferType()) {
                case "1":
                    initCompanyOrderOwnerWindow();
                    break;
                case "2":
                    initTeamOrderOwnerWindow();
                    break;
                case "3":
                    initPersonOrderOwnerWindow();
                    break;
            }
        } else {
            //报价
            mBinding.tvTitle.setText("报价详情");
            switch (mEntity.getOfferType()) {
                case "1":
                    initCompanyQuoteOwnerWindow();
                    break;
                case "2":
                    initTeamQuoteOwnerWindow();
                    break;
                case "3":
                    initPersonQuoteOwnerWindow();
                    break;
            }
        }
    }

    /**
     * 设置货主视角公司接单窗口信息
     */
    private void initCompanyOrderOwnerWindow() {
        mBinding.tvName.setText(DefaultUtil.getString(mEntity.getCompanyName()));
        //
        mList.clear();
        mList.add(new SingleItemEntity("接单运费",
                String.format("%s元/吨", NumberUtil.trim0(mEntity.getFreight())),
                R.color.color_FF6600));
        mList.add(new SingleItemEntity("预计到场时间", DateUtils.stampToDay5(mEntity.getInTime())));
        mList.add(new SingleItemEntity("地址", getAddress(mEntity)));
        mList.add(new SingleItemEntity("距装货地", getDistanceStr(mEntity.getDistance())));
        mList.add(new SingleItemEntity("状态", getOfferStatusStr(mEntity)));
        mList.add(new SingleItemEntity("联系人", DefaultUtil.getString(mEntity.getContacts())));
        mAdapter.notifyDataSetChanged();
        //设置用户操作按钮
        setOwnerOperating();
    }

    /**
     * 设置货主视角团队接单窗口信息
     */
    private void initTeamOrderOwnerWindow() {
        mBinding.tvName.setText(DefaultUtil.getString(mEntity.getTeamName()));
        //
        mList.clear();
        mList.add(new SingleItemEntity("接单运费",
                String.format("%s元/吨", NumberUtil.trim0(mEntity.getFreight())),
                R.color.color_FF6600));
        mList.add(new SingleItemEntity("预计到场时间", DateUtils.stampToDay5(mEntity.getInTime())));
        mList.add(new SingleItemEntity("车辆位置", getAddress(mEntity)));
        mList.add(new SingleItemEntity("距装货地", getDistanceStr(mEntity.getDistance())));
        mList.add(new SingleItemEntity("状态", getOfferStatusStr(mEntity)));
        mList.add(new SingleItemEntity("联系人", DefaultUtil.getString(mEntity.getContacts())));
        mAdapter.notifyDataSetChanged();
        //设置用户操作按钮
        setOwnerOperating();
    }

    /**
     * 设置货主视角个人接单窗口信息
     */
    private void initPersonOrderOwnerWindow() {
        mBinding.tvName.setText(DefaultUtil.getString(mEntity.getName()));
        //
        mList.clear();
        mList.add(new SingleItemEntity("接单运费",
                String.format("%s元/吨", NumberUtil.trim0(mEntity.getFreight())),
                R.color.color_FF6600));
        mList.add(new SingleItemEntity("预计到场时间", DateUtils.stampToDay5(mEntity.getInTime())));
        mList.add(new SingleItemEntity("承运车辆", getCarInfo(mEntity, false)));
        mList.add(new SingleItemEntity("车辆位置", getAddress(mEntity)));
        mList.add(new SingleItemEntity("距装货地", getDistanceStr(mEntity.getDistance())));
        mList.add(new SingleItemEntity("状态", getOfferStatusStr(mEntity)));
        mList.add(new SingleItemEntity("联系人", DefaultUtil.getString(mEntity.getContacts())));
        mAdapter.notifyDataSetChanged();
        //设置用户操作按钮
        setOwnerOperating();
    }

    /**
     * 设置货主视角公司报价窗口信息
     */
    private void initCompanyQuoteOwnerWindow() {
        mBinding.tvName.setText(DefaultUtil.getString(mEntity.getCompanyName()));
        //
        mList.clear();
        mList.add(new SingleItemEntity("运费报价",
                String.format("%s元/吨", NumberUtil.trim0(mEntity.getFreight())),
                R.color.color_FF6600));
        mList.add(new SingleItemEntity("预计到场时间", DateUtils.stampToDay5(mEntity.getInTime())));
        mList.add(new SingleItemEntity("地址", getAddress(mEntity)));
        mList.add(new SingleItemEntity("距装货地", getDistanceStr(mEntity.getDistance())));
        mList.add(new SingleItemEntity("状态", getOfferStatusStr(mEntity)));
        mList.add(new SingleItemEntity("联系人", DefaultUtil.getString(mEntity.getContacts())));
        mAdapter.notifyDataSetChanged();
        //设置用户操作按钮
        setOwnerOperating();
    }

    /**
     * 设置货主视角团队报价窗口信息
     */
    private void initTeamQuoteOwnerWindow() {
        mBinding.tvName.setText(DefaultUtil.getString(mEntity.getTeamName()));
        //
        mList.clear();
        mList.add(new SingleItemEntity("运费报价",
                String.format("%s元/吨", NumberUtil.trim0(mEntity.getFreight())),
                R.color.color_FF6600));
        mList.add(new SingleItemEntity("预计到场时间", DateUtils.stampToDay5(mEntity.getInTime())));
        mList.add(new SingleItemEntity("地址", getAddress(mEntity)));
        mList.add(new SingleItemEntity("距装货地", getDistanceStr(mEntity.getDistance())));
        mList.add(new SingleItemEntity("状态", getOfferStatusStr(mEntity)));
        mList.add(new SingleItemEntity("联系人", DefaultUtil.getString(mEntity.getContacts())));
        mAdapter.notifyDataSetChanged();
        //设置用户操作按钮
        setOwnerOperating();
    }

    /**
     * 设置货主视角个人报价窗口信息
     */
    private void initPersonQuoteOwnerWindow() {
        mBinding.tvName.setText(DefaultUtil.getString(mEntity.getName()));
        //
        mList.clear();
        mList.add(new SingleItemEntity("运费报价",
                String.format("%s元/吨", NumberUtil.trim0(mEntity.getFreight())),
                R.color.color_FF6600));
        mList.add(new SingleItemEntity("预计到场时间", DateUtils.stampToDay5(mEntity.getInTime())));
        mList.add(new SingleItemEntity("承运车辆", getCarInfo(mEntity, false)));
        mList.add(new SingleItemEntity("车辆位置", getAddress(mEntity)));
        mList.add(new SingleItemEntity("距装货地", getDistanceStr(mEntity.getDistance())));
        mList.add(new SingleItemEntity("状态", getOfferStatusStr(mEntity)));
        mList.add(new SingleItemEntity("联系人", DefaultUtil.getString(mEntity.getContacts())));
        mAdapter.notifyDataSetChanged();
        //设置用户操作按钮
        setOwnerOperating();
    }

    /**
     * 设置货主操作按钮
     */
    private void setOwnerOperating() {
        if (mEntity == null) {
            mBinding.clOperating.setVisibility(View.GONE);
            return;
        }
        //1已接单  2已同意  5货主未同意
        if ("1".equals(mEntity.getOfferStatus())) {
            //判断接单还是报价
            mBinding.tvBtn.setText("下单");
        } else if ("2".equals(mEntity.getOfferStatus())) {
            mBinding.tvBtn.setText("查看订单");
        } else if ("5".equals(mEntity.getOfferStatus())) {
            mBinding.tvBtn.setVisibility(View.GONE);
        }
    }

    /**
     * 获取报价状态
     */
    private String getOfferStatusStr(OrderQuoteEntity entity) {
        if (entity == null || TextUtils.isEmpty(entity.getOfferStatus())) {
            return "/";
        }
        String status = "/";
        //1已报价  2已同意  5货主未同意
        switch (entity.getOfferStatus()) {
            case "1":
                //判断接单还是报价
                status = entity.getIsVoluntarily() == 2 ? "已接单" : "已报价";
                break;
            case "2":
                status = "已同意";
                break;
            case "5":
                status = "未同意";
                break;
        }
        return status;
    }

    /**
     * 获取车辆信息
     */
    private String getCarInfo(OrderQuoteEntity entity, boolean isNeedGoneCarNumber) {
        if (entity == null) return "/";
        StringBuilder carInfo = new StringBuilder();
        //车辆信息
        if (!TextUtils.isEmpty(entity.getCarTypeName())) {
            carInfo.append("/").append(entity.getCarTypeName());
        }
        if (!TextUtils.isEmpty(entity.getCarLenName())) {
            carInfo.append("/").append("车长").append(entity.getCarLenName());
        }
        if (!TextUtils.isEmpty(entity.getHeightHurdle())) {
            carInfo.append("/").append("栏高").append(NumberUtil.trim0(entity.getHeightHurdle())).append("米");
        }
        //设置车牌号
        String carNumber;
        if (isNeedGoneCarNumber) {
            carNumber = DefaultUtil.getEncryptedString(entity.getCarNumber(), 2);
        } else {
            carNumber = entity.getCarNumber();
        }
        return String.format("%s(%s)", carNumber, carInfo.length() > 0 ? carInfo.substring(1) : carInfo.toString());
    }

    /**
     * 获取地址信息
     */
    private String getAddress(OrderQuoteEntity entity) {
        if (entity == null) return "/";
        StringBuilder address = new StringBuilder();
        //offerType 1 企业 2 团队 3 个人
        if ("3".equals(entity.getOfferType())) {
            if (!TextUtils.isEmpty(entity.getDetailAddress())) {
                address.append(entity.getDetailAddress());
            }
        } else {
            if (!TextUtils.isEmpty(entity.getCompanyTeamAddress())) {
                address.append(entity.getCompanyTeamAddress());
            }
        }
        return DefaultUtil.getString(address.toString(), "/");
    }

    /**
     * 获取距离字段
     */
    private String getDistanceStr(String distanceStr) {
        String str;
        double distance = NumberUtil.convertToDouble(distanceStr);
        if (distance <= 0) {
            str = "/";
        } else {
            str = distance < 1 ? "1km以内" : String.format("%skm", NumberUtil.trim0(distance));
        }
        return str;
    }

    /**
     * 设置联系按钮状态
     */
    private void setContactStatus(OrderQuoteEntity entity) {
        if (entity == null) return;
        //无im信息置灰消息按钮
        if (TextUtils.isEmpty(entity.getImAccount())) {
            mBinding.tvMsg.setAlpha(0.5f);
            mBinding.tvMsg.setEnabled(false);
        } else {
            mBinding.tvMsg.setAlpha(1f);
            mBinding.tvMsg.setEnabled(true);
        }
        //无手机号信息置灰联系按钮
        if (TextUtils.isEmpty(entity.getContactsNumber())) {
            mBinding.tvTel.setAlpha(0.5f);
            mBinding.tvTel.setEnabled(false);
        } else {
            mBinding.tvTel.setAlpha(1f);
            mBinding.tvTel.setEnabled(true);
        }
    }

    @Override
    public void onClick(View v) {
        if (v == mBinding.tvMsg) {
            imClick();
        } else if (v == mBinding.tvCancel) {
            dismiss();
        } else if (v == mBinding.tvTel) {
            telClick();
        } else if (v == mBinding.tvBtn) {
            //同意接单/同意报价/查看订单
            btnClick();
        }
    }

    private void imClick() {
        //检查登录状态
        if (UserOperating.getInstance().isNotLogged(mContext)) {
            return;
        }
        if (mEntity != null && !TextUtils.isEmpty(mEntity.getImAccount())) {
            IMUtils.getInstance().buildSingleTalking(mEntity.getImAccount());
        }
    }

    private void telClick() {
        //检查登录状态
        if (UserOperating.getInstance().isNotLogged(mContext)) {
            return;
        }
        if (mEntity != null && !TextUtils.isEmpty(mEntity.getContactsNumber())) {
            showTelDialog(mEntity.getContactsNumber());
        }
    }

    private void showTelDialog(String phone) {
        new RoundDialog.Builder(mContext)
                .title("是否拨打电话")
                .content(phone)
                .confirm("拨打")
                .cancelable(false)
                .confirmCallback(v -> ActivityJump.jumpToPhone(mContext, phone))
                .show();
    }

    /**
     * 操作按钮点击
     */
    private void btnClick() {
        if (mEntity == null) {
            return;
        }
        //按钮点击事件
        String btnStr = mBinding.tvBtn.getText().toString();
        switch (btnStr) {
//            case "同意接单":
//            case "同意报价":
            case "下单":
                showOfferDialog(mEntity);
                break;
            case "查看订单":
                //跳转竞价订单详情
                if (!TextUtils.isEmpty(mEntity.getOrderNo()))
                    BiddingOrderDetailsActivity.start(mContext, mEntity.getOrderNo(), mWindowType);
                break;
        }
    }

    /**
     * 展示同意报价对话框
     */
    private void showOfferDialog(OrderQuoteEntity entity) {
        String name = "";
        switch (entity.getOfferType()) {
            case "1"://企业
                name = entity.getCompanyName();
                break;
            case "2"://团队
                name = entity.getTeamName();
                break;
            case "3"://个人
                name = entity.getName();
                break;
        }
        new RoundDialog.Builder(mContext)
                .title("提示")
                .content(entity.getIsVoluntarily() == 2
                        ? String.format("您确定要同意由%s接单吗？确定后将生成竞价订单", name)
                        : String.format("您确定要同意%s的报价吗？确定后将生成竞价订单", name))
                .cancel("取消")
                .confirm("确定")
                .contentGravity(Gravity.CENTER)
                .cancelable(false)
                .confirmCallback(v -> {
                    //同意报价/接单接口
                    agreeOffer();
                })
                .show();
    }

    /**
     * 同意车主接单/报价
     */
    public void agreeOffer() {
        RequestUtil requestUtil = RequestUtil.map();
        requestUtil.add("no", mEntity.getGoodsOfferNo());
        requestUtil.add("goodsSourceNo", mEntity.getSourceNo());
        DialogHelper.showProgressDialog(mContext, "数据加载中...");
        NewAPIManager.getInstance().getLogisticsAPI().shipperAgreeOffer(requestUtil.buildMap())
                .enqueue(new ICallBack<BaseEntity>() {
                    @Override
                    public void onSuccess(BaseEntity data) {
                        //操作成功，刷新窗口，刷新外部数据
                        String no = (String) data.getData();
                        if (!TextUtils.isEmpty(no)) {
                            mEntity.setOrderNo(no);
                        }
                        mEntity.setOfferStatus("2");
                        setData(mEntity);
                        //同意回调
                        if (mCallBack != null) {
                            mCallBack.agreedOffer(mEntity);
                        }
                        //更新货源管理列表数据
                        EventBus.getDefault().post(LogisticsEvent.make(EventConstant.EVENT_GOODS_AGREED_OFFER, null));
                    }

                    @Override
                    public void onFailure(Call<BaseEntity> call, Throwable t) {
                    }

                    @Override
                    public void onFailureWithEntity(BaseEntity entity) {
                        if (APIManager.CAR_ABNORMAL.equals(entity.getCode())) {
                            showCarTipDialog(entity.getMsg());
                        } else {
                            MToast.showToast(mContext, DefaultUtil.getString(entity.getMsg()));
                        }
                    }
                });
    }

    /**
     * 车辆异常提示弹窗
     */
    private void showCarTipDialog(String content) {
        new RoundDialog.Builder(mContext)
                .title("车辆状态异常")
                .content(DefaultUtil.getString(content))
                .confirm("确定")
                .singleBtn(true)
                .contentGravity(Gravity.CENTER)
                .cancelable(false)
                .show();
    }

    @Override
    public void dismiss() {
        super.dismiss();
        clearAlpha();
    }
}
